package com.weixin.util;

/*
 * 文 件 名:  HttpTools.java
 * 版    权:  Huawei Technologies Co., Ltd. Copyright YYYY-YYYY,  All rights reserved
 * 描    述:  <描述>
 * 修 改 人:  h00101670
 * 修改时间:  2009-1-5
 * 跟踪单号:  <跟踪单号>
 * 修改单号:  <修改单号>
 * 修改内容:  <修改内容>
 */

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;

import com.weixin.vo.HttpResult;


public class HttpTools {
	/**
	 * 链接的超时数,默认为30秒,此处要做成可配置
	 */
	protected static final int CONNECTION_TIME_OUT = 10000;
	/**
	 * socket响应超时时间
	 */
	protected static final int SO_TIMEOUT = 0;
	/**
	 * 每个主机的最大并行链接数，默认为2
	 */
	protected static final int MAX_CONNECTIONS_PER_HOST = 5;
	/**
	 * 客户端总并行链接最大数，默认为20
	 */
	protected static final int MAX_TOTAL_CONNECTIONS = 100;
	/** 日志对象 */
	protected static Logger logger = Logger.getLogger(HttpTools.class);
	/**
	 * http的header中的content-type属性的名字
	 */
	protected static final String CONTENT_TYPE_NAME = "content-type";
	/**
	 * HTTP请求消息头中json内容类型的格式
	 */
	protected static String CONTENT_TYPE_VALUE_JSON_UTF_8 = "application/json; charset=UTF-8";
	
	/**
	 * HttpUtil类的实例
	 */
	private static HttpTools instance = new HttpTools();
	/**
	 * HttpClient实例
	 */
	private CloseableHttpClient httpClient = getHttpClient();

	/**
	 * HttpUtil类构造函数
	 */
	private HttpTools() {

	}

	/**
	 * 单例模式返回唯一的HttpUtil的实例 在创建HttpUtil实例的时候创建HttpClient对象，并且设置HttpClient超时的属性。
	 * 创建HttpClient实例，默认是SimpleHttpConnectionManager创建的，不支持多线程。
	 * 使用多线程技术就是说，client可以在多个线程中被用来执行多个方法。 每次调用HttpClient.executeMethod()
	 * 方法，都会去链接管理器申请一个连接实例， 申请成功这个链接实例被签出(checkout)，随之在链接使用完后必须归还管理器。 管理器支持两个设置：
	 * maxConnectionsPerHost 每个主机的最大并行链接数，默认为2 maxTotalConnections
	 * 客户端总并行链接最大数，默认为20
	 * 
	 * @return HttpUtil
	 */
	public static HttpTools getInstance() {
		return instance;
	}

	/**
	 * 构造Http客户端对象 <功能详细描述>
	 * 
	 */
	private CloseableHttpClient getHttpClient() {

		PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
		// 将最大连接数增加到200
		cm.setMaxTotal(MAX_TOTAL_CONNECTIONS);
		// 将每个路由基础的连接增加到20
		cm.setDefaultMaxPerRoute(MAX_TOTAL_CONNECTIONS / 2);

		httpClient = HttpClients.custom().setConnectionManager(cm).build();

		return httpClient;
	}

	/**
	 * 发送HTTP请求
	 * 
	 */
	public String sendHttpRequest(String url, String content, ContentType contentType)  {
		HttpPost httpMethod = new HttpPost(url);
		String responseBody= "";
		try {
			httpMethod.addHeader(CONTENT_TYPE_NAME, ContentType.APPLICATION_JSON.toString());
			HttpEntity entity = new StringEntity(content, contentType);
			httpMethod.setEntity(entity);
			// 响应失败，则抛出异常码进行处理
			CloseableHttpResponse httpResoponse = httpClient.execute(httpMethod);
			if (HttpStatus.SC_OK != httpResoponse.getStatusLine().getStatusCode()) {
				throw new Exception("The response code is error: " + httpResoponse.getStatusLine().getStatusCode());
			}
			// 处理响应体
			responseBody = EntityUtils.toString(httpResoponse.getEntity(), "UTF-8");
		} catch (Exception ex) {
			logger.error(MessageFormat.format("send http request error! the url is: {0}, para is: {1}", url, content), ex);
			httpMethod.abort();
		}
		return responseBody;
	}

	/**
	 * 发送HTTP请求
	 * 
	 */
	public String sendHttpJsonRequest(String url, String jsonString, Header[] headers)  {
		HttpPost httpMethod = new HttpPost(url);
		String responseBody = "";
		try {
			httpMethod.addHeader(CONTENT_TYPE_NAME, CONTENT_TYPE_VALUE_JSON_UTF_8);
			if (!ArrayUtils.isEmpty(headers)) {
				for (Header header : headers) {
					httpMethod.addHeader(header.getName(), header.getValue());
				}
			}
			HttpEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON);
			httpMethod.setEntity(entity);

			// 响应失败，则抛出异常码进行处理
			HttpResponse httpResoponse = httpClient.execute(httpMethod);
			if (HttpStatus.SC_OK != httpResoponse.getStatusLine().getStatusCode()) {
				throw new Exception("The response code is error! url: " + url);
			}
			// 处理响应体
			responseBody = EntityUtils.toString(httpResoponse.getEntity(), "UTF-8");

		} catch (Exception ex) {
			logger.error("send http request error!", ex);
			httpMethod.abort();
		}
		return responseBody;
	}

	/**
	 * 发送HTTP请求
	 * 
	 */
	public String sendHttpJsonRequest(String url, String jsonString, Map<String, String> params)  {
		HttpPost httpMethod = new HttpPost(url);
		String responseBody = "";
		try {
			httpMethod.addHeader(CONTENT_TYPE_NAME, CONTENT_TYPE_VALUE_JSON_UTF_8);
			// 设置参数数据
			if (params != null) {
				for (Map.Entry<String, String> entry : params.entrySet()) {
					httpMethod.addHeader(entry.getKey(), entry.getValue());
				}
			}
			HttpEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON);
			httpMethod.setEntity(entity);
			HttpResponse httpResoponse = httpClient.execute(httpMethod);
			if (HttpStatus.SC_OK != httpResoponse.getStatusLine().getStatusCode()) {
				// 响应失败，则抛出异常码进行处理
				throw new Exception("The response code is error! url: " + url);
			}
			// 处理响应体
			responseBody = EntityUtils.toString(httpResoponse.getEntity(), "UTF-8");
			
		} catch (Exception ex) {
			logger.error("send http request error!", ex);
			httpMethod.abort();
		}
		
		return responseBody;
	}
	
	/**
	 * 发送HTTP请求
	 * 
	 */
	public HttpResult sendHttpInputStreamRequest(String url,  InputStream is,Map<String, String> hearderMap)  {
		return sendHttpInputStreamRequest(url, is, hearderMap,null);
	}

	/**
	 * 发送HTTP请求
	 * 
	 */
	public HttpResult sendHttpInputStreamRequest(String url,  InputStream is,Map<String, String> hearderMap,Map<String, String> params)  {
		HttpPost httpMethod = new HttpPost(url);
		HttpResult result= new HttpResult();
		HttpResponse httpResoponse = null;
		try {
			httpMethod.addHeader(CONTENT_TYPE_NAME, CONTENT_TYPE_VALUE_JSON_UTF_8);
			// 设置参数数据
			if (hearderMap != null) {
				for (Map.Entry<String, String> entry : hearderMap.entrySet()) {
					if("host".equalsIgnoreCase(entry.getKey())){
						continue;
					}
					httpMethod.addHeader(entry.getKey(), entry.getValue());
				}
			}
			if(is !=null){
				InputStreamEntity  entity = new InputStreamEntity(is);
				httpMethod.setEntity(entity);
			}
		
			httpResoponse = httpClient.execute(httpMethod);
			for ( Header h : httpResoponse.getAllHeaders()) {
				result.getResultHeaderMap().put(h.getName(), h.getValue());
			}
			if (HttpStatus.SC_OK != httpResoponse.getStatusLine().getStatusCode()) {
				StringBuffer msg =new  StringBuffer();
				// 响应失败，则抛出异常码进行处理
				throw new Exception("The response code is error! url: " + url+",info:"+msg.toString());
			}
			
			HttpEntity entity = httpResoponse.getEntity();  
			result.setIs(entity.getContent());
			
	
		} catch (Exception ex) {
			logger.error("send http request error!", ex);
			httpMethod.abort();
		}
		return result;
	}
	
	
	
	public static HttpResult sendPostByConnection(String url,InputStream is,Map<String, String> hearderMap,Map<String, String> params) throws Exception {  
        // 作为StringBuffer初始化的字符串  
	 HttpResult result= new HttpResult();
	 HttpURLConnection urlConnection = null;
        try {  
            URL realUrl = new URL(url);  
            urlConnection = (HttpURLConnection) realUrl.openConnection();  
            urlConnection.setConnectTimeout(3000);  
            urlConnection.setRequestMethod("POST");  
            urlConnection.setDoInput(true);// 表示从服务器获取数据  
            urlConnection.setDoOutput(true);// 表示向服务器写数据  
            
        	// 设置参数数据
			if (hearderMap != null) {
				for (Map.Entry<String, String> entry : hearderMap.entrySet()) {
					urlConnection.setRequestProperty(entry.getKey(), entry.getValue());
				}
			}
            
            // 获得输出流,向服务器输出数据  
            OutputStream outputStream = urlConnection.getOutputStream();
            
            byte[] buffer=new byte[4096];  
			int ch = 0;
			while ((ch = is.read(buffer)) != -1) {
				outputStream.write(buffer,0,ch);
				outputStream.flush();
			}
            
            outputStream.close();
            
            // 获得服务器响应的结果和状态码  
            int responseCode = urlConnection.getResponseCode();  
            Map<String, List<String>> requestProMap = urlConnection.getHeaderFields();
            
            if(requestProMap !=null){
            	Set<Entry<String, List<String>>> keySet = requestProMap.entrySet();
            	for (Entry<String, List<String>> entry : keySet) {
					if(entry.getValue().size()>1){
						result.getResultHeaderMap().put(entry.getKey(),Arrays.toString(entry.getValue().toArray()));
					}else{
						result.getResultHeaderMap().put(entry.getKey(),entry.getValue().get(0));
					}
				}
            }
            
            if (responseCode != 200) {
				// 响应失败，则抛出异常码进行处理
				throw new Exception("The response code is error! url: " + url);	            	
            }  
            
            result.setIs(urlConnection.getInputStream());
            
        } catch (UnsupportedEncodingException e) {  
        	if(urlConnection !=null){
        		urlConnection.disconnect();
        	}
            e.printStackTrace();  
        } catch (IOException e) {  
            e.printStackTrace();  
        	if(urlConnection !=null){
        		urlConnection.disconnect();
        	}
        }finally{
        	if(is !=null){
        		try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
        	}
        }
        return result;  
	}  
	
	/**
	 * 发送MultiPart请求
	 * 
	 * 
	 * <form action="url"  method="post" enctype="multipart/form-data">
	 * 		<input type="file" name="file1"/>
	 * 		<input type="text" name="username" />
	 * </form>
	 * 
	 * 对应map:
	 * map.put("file1",new File(全路径));
	 * map.put("username","value");
	 */
	public HttpResult sendMultiPartRequest(String url,  Map<String,Object> map,Map<String,String> headers)  {
		HttpPost httpMethod = new HttpPost(url);
		HttpResult result= new HttpResult();
		
		try {
			MultipartEntityBuilder builder = MultipartEntityBuilder.create();
			builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
			// 设置参数数据
			if (headers != null) {
				for (Map.Entry<String, String> entry : headers.entrySet()) {
					if("host".equalsIgnoreCase(entry.getKey())){
						continue;
					}
					httpMethod.addHeader(entry.getKey(), entry.getValue());
				}
			}
			
			if (map != null) {
				for (String key : map.keySet()) {
					Object value = map.get(key);
					if(value instanceof File){
						File _value = (File)value;
						builder.addBinaryBody(key, _value, ContentType.DEFAULT_BINARY, key);
					}else{
						StringBody strBody = new StringBody(value.toString(), ContentType.MULTIPART_FORM_DATA);
						builder.addPart(key, strBody);
//						builder.addTextBody(key, value.toString(), ContentType.DEFAULT_BINARY);
					}
				}
			}
			
			HttpEntity reqentity = builder.build();
			httpMethod.setEntity(reqentity);  
			
			HttpResponse httpResoponse = httpClient.execute(httpMethod);
			if (HttpStatus.SC_OK != httpResoponse.getStatusLine().getStatusCode()) {
				// 响应失败，则抛出异常码进行处理
				throw new Exception("The response code is error! url: " + url);
			}
			for ( Header h : httpResoponse.getAllHeaders()) {
				result.getResultHeaderMap().put(h.getName(), h.getValue());
			}
			
			HttpEntity entity = httpResoponse.getEntity();  
			result.setIs(entity.getContent());
			
	
		} catch (Exception ex) {
			logger.error(ex,ex);
			httpMethod.abort();
		}
		return result;
	}
	
	/**
	 * 发送application/x-www-form-urlencoded请求
	 * 
	 * 
	 * <form action="url"  method="post">
	 * 		<input type="text" name="username" />
	 * </form>
	 * 
	 * 对应map:
	 * map.put("username","py");
	 */
	public HttpResult sendUrlEncodedFormRequest(String url,  Map<String,String> params,Map<String,String> headers)  {
		HttpPost httpMethod = new HttpPost(url);
		HttpResult result= new HttpResult();
		
		try {
			// 设置参数数据
			if (headers != null) {
				for (Map.Entry<String, String> entry : headers.entrySet()) {
					if("host".equalsIgnoreCase(entry.getKey())){
						continue;
					}
					httpMethod.addHeader(entry.getKey(), entry.getValue());
				}
			}
			if(params !=null && params.size()>0){
				List<NameValuePair> formparams = new ArrayList<NameValuePair>();
				for (Map.Entry<String, String> entry : params.entrySet()) {
					formparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue().toString()));
				}
				UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
				httpMethod.setEntity(entity);
			}
		
			HttpResponse httpResoponse = httpClient.execute(httpMethod);
			if (HttpStatus.SC_OK != httpResoponse.getStatusLine().getStatusCode()) {
				// 响应失败，则抛出异常码进行处理
				throw new Exception("The response code is error! url: " + url);
			}
			for ( Header h : httpResoponse.getAllHeaders()) {
				String hvalue = h.getValue();
				result.getResultHeaderMap().put(h.getName(), hvalue);
			}
			
			
			HttpEntity entity = httpResoponse.getEntity();  
			result.setIs(entity.getContent());
			
	
		} catch (Exception ex) {
			logger.error(ex,ex);
			httpMethod.abort();
		}
		
		
		return result;
	}

	/**
	 * 文件下载
	 * 
	 */
	public File downloadFile(String downloadFilePath) {
		HttpPost httpMethod = new HttpPost(downloadFilePath);
		InputStream resStream = null;
		File temp = null;
		try {
			// 响应失败，则抛出异常码进行处理
			HttpResponse httpResoponse = httpClient.execute(httpMethod);
			if (HttpStatus.SC_OK != httpResoponse.getStatusLine().getStatusCode()) {
				throw new Exception("The response code is error! downloadFilePath: " + downloadFilePath);
			}

			// 处理响应体
			resStream = httpResoponse.getEntity().getContent();
			temp = File.createTempFile(UUID.randomUUID().toString(), ".tmp");
			FileOutputStream fos = new FileOutputStream(temp);
			IOUtils.copy(resStream, fos);

			
		} catch (Exception ex) {
			logger.error("send http request error!", ex);
			httpMethod.abort();
		} finally {
			if (resStream != null) {
				try {
					resStream.close();
				} catch (IOException e) {
				}
			}
		}
		return temp;
	}

	/**
	 * 文件下载
	 * 
	 */
	public File downloadFileByURL(String fileURL)  {
		HttpPost httpMethod = new HttpPost(fileURL);
		InputStream resStream = null;
		File  temp = null;
		try {
			// 响应失败，则抛出异常码进行处理
			HttpResponse httpResoponse = httpClient.execute(httpMethod);
			if (HttpStatus.SC_OK != httpResoponse.getStatusLine().getStatusCode()) {
				throw new Exception("The response code is error! url: " + fileURL);
			}

			// 文件后缀
			String suffix = StringUtils.substringAfterLast(fileURL, ".");

			// 处理响应体
			resStream = httpResoponse.getEntity().getContent();
			temp = File.createTempFile(UUID.randomUUID().toString(), StringUtils.isEmpty(suffix) ? ".tmp" : "." + suffix);
			FileOutputStream fos = new FileOutputStream(temp);
			IOUtils.copy(resStream, fos);

			return temp;
		} catch (Exception ex) {
			logger.error("send http request error!", ex);
			httpMethod.abort();
		} finally {
			if (resStream != null) {
				try {
					resStream.close();
				} catch (IOException e) {
				}
			}
		}
		return temp;
	}

	/**
	 * 文件下载(跟读题音频文件下载)
	 * 
	 * @param url
	 * @return
	 * @throws Exception
	 */
	public File downloadSpeechFile(String content)  {
		InputStream resStream = null;
		HttpPost httpMethod = null;
		File temp = null;
		try {
			content = URLEncoder.encode(content, "UTF-8");
			String url = "http://translate.google.com/translate_tts?tl=en&q=" + content;
			httpMethod = new HttpPost(url);

			// 响应失败，则抛出异常码进行处理
			HttpResponse httpResoponse = httpClient.execute(httpMethod);
			if (HttpStatus.SC_OK != httpResoponse.getStatusLine().getStatusCode()) {
				// 当http返回的是非200的状态则立即终止连接，抛出异常告知客户端;
				httpMethod.abort();
				throw new Exception("The response code is error! url: " + url);
			}

			// 处理响应体
			resStream = httpResoponse.getEntity().getContent();
			temp = File.createTempFile(UUID.randomUUID().toString(), ".mp3");
			FileOutputStream fos = new FileOutputStream(temp);
			IOUtils.copy(resStream, fos);

			return temp;
		} catch (Exception ex) {
			logger.error("send http request error!", ex);
			httpMethod.abort();
		} finally {
			if (resStream != null) {
				try {
					resStream.close();
				} catch (IOException e) {
				}
			}
		}
		return temp;
	}

	/**
	 * 通过URL传递参数来发送请求
	 * 
	 */
	public String sendHttpRequest(String url, Map<String, Object> para)  {
		HttpPost httpMethod = null;
		String responseBody =null;
		
		try {
			StringBuilder sb = new StringBuilder();
			sb.append(url);
			if (MapUtils.isNotEmpty(para)) {
				sb.append("?");
				for (String key : para.keySet()) {
					sb.append(key).append("=").append(para.get(key)).append("&");
				}
			}
			httpMethod = new HttpPost(sb.toString());
			HttpResponse httpResoponse = httpClient.execute(httpMethod);
			if (HttpStatus.SC_OK != httpResoponse.getStatusLine().getStatusCode()) {
				// 响应失败，则抛出异常码进行处理
				throw new Exception("The response code is error! url: " + url);
			}
			// 处理响应体
			responseBody = EntityUtils.toString(httpResoponse.getEntity(), "UTF-8");
			return responseBody;
		} catch (Exception ex) {
			logger.error("send http request error!", ex);
			if (httpMethod != null) {
				httpMethod.abort();
			}
		}
		return responseBody;
	}

	/**
	 * 
	 * @param method
	 * @param url
	 * @param urlParams
	 *            请求参数，请求参数应该是 name1=value1&name2=value2 的形式
	 * @return
	 * @
	 */
	public String sendHttpRequest(String method, String url, String urlParams)  {
		HttpRequestBase httpMethod = null;
		String responseBody = "";
		try {
			StringBuilder sb = new StringBuilder();
			sb.append(url);
			if (StringUtils.isNotEmpty(urlParams)) {
				sb.append("?");
				sb.append(urlParams);
			}
			if ("POST".equalsIgnoreCase(method)) {
				httpMethod = new HttpPost(sb.toString());
			} else {
				httpMethod = new HttpGet(sb.toString());
			}
			HttpResponse httpResoponse = httpClient.execute(httpMethod);
			if (HttpStatus.SC_OK != httpResoponse.getStatusLine().getStatusCode()) {
				// 响应失败，则抛出异常码进行处理
				throw new Exception("The response code is error! url: " + url);
			}
			// 处理响应体
			responseBody = EntityUtils.toString(httpResoponse.getEntity(), "UTF-8");
			return responseBody;
		} catch (Exception ex) {
			logger.error("send http request error!", ex);
			if (httpMethod != null) {
				httpMethod.abort();
			}
		}
		return responseBody;
	}

	/**
	 * 判断url是否存在
	 * 
	 * @return[参数、异常说明] @return boolean [返回类型说明]
	 * @see [类、类#方法、类#成员]
	 */
	public boolean isUrlExist(String url) {
		HttpPost httpMethod = new HttpPost(url);
		HttpResponse httpResoponse = null;
		try {
			httpResoponse = httpClient.execute(httpMethod);
		} catch (Exception e) {
			logger.error("send http request error!", e);
			httpMethod.abort();
			return false;
		}

		return HttpStatus.SC_OK == httpResoponse.getStatusLine().getStatusCode();

	}

	/**
	 * 异步发送HTTP请求 无需等待
	 * 
	 * @param url
	 *            URL地址
	 * @param xml
	 *            消息体
	 * @return
	 * @throws PortalException
	 * @see [类、类#方法、类#成员]
	 */
	public void sendAsynchHttpJsonRequest(final String url, final String jsonString)  {
		new Thread() {
			public void run() {
				HttpPost httpMethod = new HttpPost(url);
				try {
					httpMethod.addHeader(CONTENT_TYPE_NAME, CONTENT_TYPE_VALUE_JSON_UTF_8);
					HttpEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON);
					httpMethod.setEntity(entity);
					// 响应失败，则抛出异常码进行处理
					HttpResponse httpResoponse = httpClient.execute(httpMethod);
					if (HttpStatus.SC_OK != httpResoponse.getStatusLine().getStatusCode()) {
						throw new Exception("The response code is error: " + httpResoponse.getStatusLine().getStatusCode());
					}
				} catch (Exception ex) {
					logger.error(MessageFormat.format("send http request error! the url is: {0}, para is: {1}", url, jsonString), ex);
					httpMethod.abort();
				}
			}
		}.start();
	}

	/**
	 * 向指定URL发送GET方法的请求
	 * 
	 */
	public static String sendGet(String url, String jsonString)  {
		return HttpTools.getInstance().sendHttpJsonRequest(url, jsonString, new HashMap<String, String>());
	}

	/**
	 * 向指定 URL 发送POST方法的请求
	 * 
	 */
	public static String sendPost(String url, String jsonString)  {
		return HttpTools.getInstance().sendHttpJsonRequest(url, jsonString, new HashMap<String, String>());
	}
}
